package com.quyeying.service.impl;

import com.quyeying.entity.TblOrderProductEntity;
import com.quyeying.mapper.TblOrderProductDao;
import com.quyeying.service.TblOrderProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.quyeying.utils.result.R;
import com.quyeying.utils.result.ReturnPageData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;

/**
* <p>
 * 订单商品信息表 服务实现类
 * </p>
*
* @author skx
* @since 2022-07-19
*/
@Service
public class TblOrderProductServiceImpl extends ServiceImpl<TblOrderProductDao, TblOrderProductEntity> implements TblOrderProductService {

    @Override
    public R findListByPage(Integer page, Integer pageCount){
        IPage<TblOrderProductEntity> wherePage = new Page<>(page, pageCount);
        TblOrderProductEntity where = new TblOrderProductEntity();
        IPage<TblOrderProductEntity> iPage = baseMapper.selectPage(wherePage, Wrappers.query(where));
        return R.success(ReturnPageData.fillingData(iPage));
    }

    @Override
    public R add(TblOrderProductEntity tblOrderProductEntity){
        baseMapper.insert(tblOrderProductEntity);
        return R.success();
    }

    @Override
    public R delete(Long id){
        baseMapper.deleteById(id);
        return R.success();
    }

    @Override
    public R updateData(TblOrderProductEntity tblOrderProductEntity){
        baseMapper.updateById(tblOrderProductEntity);
        return R.success();
    }

    @Override
    public R findById(Long id){
        TblOrderProductEntity tblOrderProductEntity = baseMapper.selectById(id);
        return R.success(tblOrderProductEntity);
    }

    /**
     * 获取订单商品信息and商品浏览量
     *
     * @param orderId
     */
    @Override
    public List<TblOrderProductEntity> getOrderProductAndBrowse(Long orderId) {
        return baseMapper.getOrderProductAndBrowse(orderId);
    }
}
